<template>
	<view class="background">
		<view class="line">
			<text class="lineName">{{ detail.fromCity }}</text>
			<image
				class="rightIcon"
				src=""
				mode=""
			></image>
			<text class="lineName">{{ detail.endCity }}</text>
		</view>
		<view class="fromTime">
			<text>出发时间：{{detail.fromTime}}</text>
		</view>
		<view class="ckInfo">
			<view class="tInfo">
				<view class="dItem">
					<text>{{ detail.passengerName }} {{ detail.passengerPhone }}</text>
					<!-- <text class="total">¥ {{ detail.actualAmount }}</text> -->
				</view>
				<view class="dItem">
					<text class="circle startCircle"></text>
					<text>{{ detail.stationUp }}</text>
					<!-- <text>{{ checkState(x.orderState) }}</text> -->
				</view>
				<view class="dItem">
					<text class="circle endCircle"></text>
					<text>{{ detail.stationOf }}</text>
				</view>
			</view>
		</view>
		<view class="hxWrap">
			<button type="primary" @click="hexiao">核销</button>
		</view>
	</view>
</template>

<script>
var openid;
import api from '../../api';
export default {
	components: {},
	data() {
		return {
			detail: '',
			orderDetailId: ''
		};
	},
	onLoad(option) {
		this.orderDetailId = JSON.parse(option.orderDetailId);
		console.log('orderDetailId');
		console.log(typeof this.orderDetailId);
		this.getOrderDetail(option.orderDetailId);
	},
	methods: {
		hexiao(){
			api.order.isCheck({orderDetailId:this.detail.orderDetailId}).then(res=>{
				if(res.code == 200){
					uni.showToast({
						title: '核销成功',
						duration: 1500,
						icon: 'none',
					});
					this.scanCode()
				}else{
					uni.showToast({
						title: res.msg,
						duration: 1500,
						icon: 'none',
					});
				}
			})
		},
		scanCode(){
			uni.scanCode({
			    success: function (res) {
			        console.log('条码类型：' + res.scanType);
			        console.log('条码内容：' + res.result);
					api.order.isCheck({orderDetailId:this.detail.orderDetailId}).then(res=>{
						if(res.code == 200){
							this.hexiao()
						}
					})
					
			    }
			});
		},
		backMoney(orderId) {
			let that = this;
			uni.showModal({
				content: '确定要退款吗？',
				success(res) {
					api.order.refundById({ orderId }).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: '退款成功',
								duration: 1500,
								icon: 'none'
							});
							that.getOrderDetail(that.item.orderId);
						} else {
							uni.showToast({
								title: res.msg,
								duration: 3000,
								icon: 'none'
							});
						}
					});
				}
			});
		},
		cancel(id) {
			console.log(id);
			let that = this;
			uni.showModal({
				content: '确定取消订单？',
				success(res) {
					console.log('cencel');
					api.order.queryPayState().then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: '取消订单成功',
								duration: 1500,
								icon: 'none'
							});
							that.getOrderDetail(that.item.orderId);
						} else {
							uni.showToast({
								title: res.msg,
								duration: 3000,
								icon: 'none'
							});
						}
					});
				}
			});
		},

		checkState(state) {
			if (state == 1) {
				return '待支付';
			} else if (state == 5) {
				return '待出行';
			} else if (state == 6) {
				return '已出行';
			} else if (state == 7) {
				return '已取消';
			} else if (state == 9) {
				return '退款中';
			} else if (state == 10) {
				return '退款成功';
			} else if (state == 11) {
				return '取消退款';
			}
		},
		getOrderDetail(orderDetailId) {
			api.order.checkInfoByDetailId({orderDetailId}).then(res=>{
				if (res.code == 200) {
					this.detail = res.data;
				}else{
					uni.showToast({
						title: res.msg,
						duration: 1500,
						icon: 'none',
					});
				}
			})
			// api.order.queryOrderStateAndDetailId({ orderId }).then(res => {
			// 	if (res.code == 200) {
			// 		this.detail = res.data;
			// 	}
			// });
		},
		// 支付
		pay(billId, billCrateTime) {
			var time = (new Date().getTime() - new Date(billCrateTime).getTime()) / 1000 / 60;
			if (time > 10) {
				uni.showToast({
					title: '待支付时间已超过10分钟',
					duration: 1500,
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.background {
	padding: 30upx;
}

.hxWrap{
	margin: 40upx 100upx;
}

.ckInfo {
	display: flex;
	padding: 30upx;
	border: 1px solid #eeeeee;
	border-radius: 20upx;
	
	.tInfo{
		flex: 1;
	}

	.dItem {
		margin: 10upx 0;
		display: flex;
		align-items: center;

		.total {
			flex: 1;
			text-align: right;
			color: red;
			font-size: 34upx;
		}

		.state {
			flex: 1;
			text-align: right;
		}

		.circle {
			display: inline-block;
			width: 16upx;
			height: 16upx;
			border-radius: 16upx;
			margin-right: 10upx;
		}

		.startCircle {
			background-color: #dfe20d;
		}

		.endCircle {
			background-color: #09bb07;
		}
	}
}

.fromTime{
	display: flex;
	justify-content: center;
	padding-bottom: 20upx;
}

.line {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 30upx;

	.lineName {
		font-size: 34upx;
	}
	.rightIcon {
		width: 48upx;
		height: 48upx;
	}
}

.codeWrap {
	display: flex;
	align-items: flex-end;
	margin-top: 20upx;
	text-align: right;

	.btnWrap {
		flex: 1;
		text-align: right;
	}
}
</style>
